<template>
    <div>
        <h1>一个人的信息</h1>
        <button @click="sum++">+</button>sum：{{sum}}
        <br>
        <button @click="msg = msg.concat('~')">+</button>msg：{{msg}}
        <br>
        姓：<input type="text" v-model="person.firstName">
        <br>
        名：<input type="text" v-model="person.lastName">
        <br>
        全名：<input type="text" v-model="person.fullName">
    </div>
</template>

<script>
import {reactive,ref, watch,watchEffect} from "vue";

export default {
    name: 'App',
    setup(){
        let sum = ref(0)
        let msg = ref('你好啊')
        let person = reactive({
            firstName: '张',
            lastName: '三',
        })

        watch(sum, (newVal, oldVal) => {
            console.log('sum: ', newVal,oldVal);
        })
        watch(person,(newVal, oldVal) => {
            console.log('person: ', newVal.firstName,oldVal.firstName);
        }, {deep: true})

        watchEffect(()=>{
            const x = person.firstName;
            const x2 = person.lastName;
            const y = sum;
            person.fullName = x + '-'+ x2;
            console.log('watchEffect ......',x, y.value);
        })
        return {
            sum,
            msg,
            person

        }
    }
}
</script>

<style>
#app {
    font-family: Avenir, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-align: center;
    color: #2c3e50;
    margin-top: 60px;
}
</style>
